dojo.declare("DCustomerHomePg", wm.Page, {
    start: function() {
        this.vVendorMinAmount = 0;

        //this.svProjectServices.input.setValue("projectId", wm.Page.getPage("Main").vProjectId);
        //this.svProjectServices.update();
    },
    "preferredDevice": "desktop",

    listProjectServicesSelect1: function(inSender, inItem) {
        // var serviceId = this.listProjectServices.selectedItem.data.serviceId;
        // this.listProjectServiceVendors.setDataSet(this.svProjectAllVendors.setQuery({
        //      serviceId: serviceId
        //  }));
    },
    listProjectServicesSelect: function(inSender, inItem) {
        this.vPageBack = "VENDORS";
        // this.svProjectSvcVendors.input.setValue("projectId", wm.Page.getPage("MobileMainPg").vProjectId);
        // this.svProjectSvcVendors.update();
        this.layerVendors.activate();

    },

    listProjectServicesCustomeraddressFormat: function(inValue, rowId, cellId, cellField, cellObj, rowObj) {

        if (inValue) {
            return inValue;
        } else {
            return "";
        }

    },
    tbServicesClick1: function(inSender) {

        // this.listProjectServices.clear();
        //this.svProjectServices.clearData();
        // this.svProjectServices.update();
    },
    layerVendorItemsShow: function(inSender) {
        if (wm.Page.getPage("DMCustomerOrderSelectPg")) {
            wm.Page.getPage("DMCustomerOrderSelectPg").lvVendorItems.clearData();
            wm.Page.getPage("DMCustomerOrderSelectPg").lvVendorItems.update();
        }

    },

    layerVendorClosedShow: function(inSender) {
        this.layerVendorItemsShow(inSender);
    },
    tbPastOrdersClick1: function(inSender) {
        var customerPg = wm.Page.getPage("DCustomerOrderHistoryPg");
 this.vPageBack = "CUSTOMER_HISTORY";
        if (customerPg) {

            customerPg.lvMyOrders.update();



        }
    },
    checkVendorShopTime: function(inSender, inItem) {
        var selectedData = inSender.selectedItem.getData();
        this.vVendorMinAmount = selectedData.minOrderAmt;

        this.svShopTime.update();

    },
    svShopTimeSuccess: function(inSender, inDeprecated) {
        //  alert(inSender.getData().dataValue);
        var shopTime = inSender.getData().dataValue;
        var index = this.listProjectServices.getSelectedIndex();

        this.vPageBack = "VENDOR_ITEMS";


        if (index != -1) {
            var ptoVar = this.listProjectServiceVendors.selectedItem.data.customer.data.pto;
            var ptoMsg = this.listProjectServiceVendors.selectedItem.data.customer.data.ptoMessage;
            if (ptoMsg === null || ptoMsg.length === 0 || ptoMsg === "") {
                ptoMsg = "Shop is closed";
            }
            if (ptoVar) {

                this.layerVendorClosed.activate();
                this.labelVendorClosed.setCaption(ptoMsg);
            } else {
                if (shopTime) {
                    this.svItemCategory.update();
                    if (wm.Page.getPage("DMCustomerOrderSelectPg")) {
                        wm.Page.getPage("DMCustomerOrderSelectPg").layerSelectCategory.activate();
                    }
                    this.layerVendorItems.activate();

                } else {
                    this.layerVendorClosed.activate();
                    this.labelVendorClosed.setCaption(ptoMsg);
                }

            }

        }
    },
    svProjectServicesSuccess: function(inSender, inDeprecated) {

    },
    svProjectAllVendorsSuccess: function(inSender, inDeprecated) {

    },
    svItemCategorySuccess: function(inSender, inDeprecated) {


    },
      backClick: function(inSender) {

        if (this.vPageBack === 'VENDORS') {

            this.layerServices.activate();

        }
        if (this.vPageBack === 'VENDOR_ITEMS') {
            this.layerVendors.activate();
            this.vPageBack = 'VENDORS';

        }
        if (this.vPageBack === 'VENDOR_ITEM_CATEGORY') {
            if (wm.Page.getPage("DMCustomerOrderSelectPg")) {
                wm.Page.getPage("DMCustomerOrderSelectPg").layerSelectCategory.activate();
            }
            this.vPageBack = 'VENDOR_ITEMS';

        }
        if (this.vPageBack === 'CHECK_OUT') {

            if (wm.Page.getPage("DMCustomerOrderSelectPg")) {
                wm.Page.getPage("DMCustomerOrderSelectPg").layerSelectOrder.activate();
            }
            this.vPageBack = 'VENDOR_ITEM_CATEGORY';
        }

        if (this.vPageBack === 'CONFIRM_ORDER') {

            if (wm.Page.getPage("DMCustomerOrderSelectPg")) {
                wm.Page.getPage("DMCustomerOrderSelectPg").refreshVendorItemList();
                wm.Page.getPage("DMCustomerOrderSelectPg").txtSearch.clear();
                wm.Page.getPage("DMCustomerOrderSelectPg").layerSelectOrder.activate();
            }
            this.vPageBack = 'VENDOR_ITEM_CATEGORY';
        }
        if (this.vPageBack === 'CUSTOMER_HISTORY') {
            this.layerOrderHistory.activate();
            if (wm.Page.getPage("DMCustomerOrderHistoryPg")) {
                wm.Page.getPage("DMCustomerOrderHistoryPg").layerOrders.activate();
            }

        }

        if (this.vPageBack === 'CUSTOMER_ACCOUNT') {
            this.layerMyAccount.activate();


        }


    },
    tbUpdateAccountClick1: function(inSender) {
	this.vPageBack = 'CUSTOMER_ACCOUNT';
	},
	back1Click: function(inSender) {
	  this.backClick(inSender);
	},
  BackClick1: function(inSender) {
	  this.tbServicesClick1(inSender);
	},
  tbServices1Click1: function(inSender) {
	  this.tbServicesClick1(inSender);
	},
  _end: 0
});